********************************************************************************
********************************************************************************
***
*** Filename: 	Free-Black-Rights.do
*** Author: 	David A Bateman
*** Function: 	Reproduces figures and tables for the analyses of Free Black
***				rights and abolition in Virginia, North Carolina, Tennessee,  
***				and (included in online appendix) Mississippi. 
***	Last update: January 1, 2023
***
********************************************************************************
********************************************************************************

cd "..\Deeper Roots"
set more off

********************************************************************************
*** Open VA, NC, and TN roll call files. First generate Figures 5 and 6 and then
*** Figure A6 (Mississippi in online appendix). 
********************************************************************************
*** VA
use "Dataverse\Files\Virginia-1831-1832-Roll-Calls.dta", clear

foreach x of varlist rc* {

	logit `x'  perEnslaved perFBlack
	qui margins, at(perEnslaved = (0(10)60))
	marginsplot, recastci(rarea) recast(line) 	///
		graphreg(col(none)) name(`x', replace)	///
		xtitle("") ylab(,angle(h) nogrid)		///
		ytitle("") title("`: variable label `x''", size(small) col(black))	///
		ci1opts(col(gs14) lcol(gs14)) plot1opts(lcol(black))
}

graph combine rc1831a rc1831b rc1832a rc1832b rc1832c rc1832d, 	///
	row(2) ycommon imargin(tiny) graphreg(col(white)) 			///
	note("Predicted probabilities from logit regression, controlling for free African American population", size(small))	///
	b1title("Percentage of County Held in Slavery", size(small) col(black)) 				///
	l1title("Probability of Voting Yea", size(small) col(black)) name(graph1, replace)
	
*** Figure 5: "Predicted Probabilities of Voting on Slavery, Removal, and Civil Disabilities in Virginia"
graph export "Dataverse\Figures\Figure-5.pdf", as(pdf) replace

********************************************************************************
*** TN and NC	
use "Dataverse\Files\NC-TN-1834-1835-Roll-Calls.dta", clear

logit bsuff c.perEnslaved##i.state_id
margins, over(state_id) at(perEnslaved = (0(5)50))
marginsplot, recastci(rarea) recast(line)						///
	ci1opts(col(gs10) lw(thin) lc(gs14))						///
	ci2opts(recast(rline) col(none) lw(thin) lc(black) lp(dash))	///
	plot1opts(lc(black)) plot2opts(lc(black) lp(dash))			///
	graphregion(color(none)) ylabel(, labsize(small) nogrid angle(h))	///
	xlab(, labsize(small)) 										///
	xtitle("Percentage of County Held in Slavery", size(small))	///
	ytitle("Probability of Voting for Disenfranchisement", size(small))	///
	name(NCTN, replace)										///
	title("Free Black Disenfranchisement", col(black) size(small))

logit AntiAbolition perEnslaved perFBlack
margins, at( perEnslaved==(0(5)40))
marginsplot, recastci(rarea) recast(line)						///
	ci1opts(col(gs10) lw(thin) lc(gs14))						///
	plot1opts(lc(black))		///
	graphregion(color(none)) ylabel(, labsize(small) nogrid angle(h))	///
	xlab(, labsize(small)) 										///
	xtitle("Percentage of County Held in Slavery", size(small))	///
	ytitle("Probability of Voting to Prohibit Abolition", size(small))	///
	name(TN, replace)		 	legend(off)									///
	title("Prohibit Abolition in Tennessee", col(black) size(small))


*** Figure 6: "Anti-Abolition and Black Disenfranchisement in TN and NC"
grc1leg TN NCTN, ycommon graphreg(col(white)) imargin(tiny) legendfrom(NCTN)
graph export "Dataverse\Figures\Figure-6.pdf", as(pdf) replace

********************************************************************************
*** MS (Online appendix)
use "Dataverse\Files\MS-1831-Roll-Calls.dta", clear

foreach x of varlist vote* {

	logit `x'  perenslaved perfblack
	qui margins, at(perenslaved = (0(10)60))
	marginsplot, recastci(rarea) recast(line) 	///
		graphreg(col(none)) name(`x', replace)	///
		xtitle("") ylab(,angle(h) nogrid)		///
		ytitle("") title("`: variable label `x''", size(small) col(black))	///
		ci1opts(col(gs14) lcol(gs14)) plot1opts(lcol(black))
}

*** Figure A6: "Mississippi�s Expulsion Bill, 1831"
graph combine vote2 vote3 vote4 vote5, graphreg(col(white)) imargin(tiny) row(1) ycommon	///
	title("Mississippi's Free Black Expulsion Act, 1831", size(small) col(black))			///
	b1title("Percentage of County Held in Slavery", size(small) col(black)) 				///
	l1title("Probability of Voting Yea", size(small) col(black)) name(graph1, replace)		///
	note("Predicted probabilities from logit regression, controlling for free African American population", size(vsmall))
graph export "Dataverse\Figures\Figure-A6.pdf", as(pdf) replace


********************************************************************************
*** In the online appendix we replicate the analyses above but instrumenting for
*** cotton suitability. We begin by providing some descriptive information about
*** the relationship between slavery and different crops, and between these
*** crops and cotton suitability.
********************************************************************************

*** Import file with cotton suitability for 1830 counties. The numbers are 
*** interpolated using an elaboration of the Acharya, Blackwell, and Sen (2016) 
*** replication file Interpolation.R. The revised file is Interpolation-1830.R 
import delimited using "Dataverse\Files\Cotton-Suitability-1830.csv", clear
destring sprop1830, force replace
gen perEnslaved1830 = sprop1830 *100

*** Merge in agricultural census from 1840. There was no agricultural census
*** in 1830. 
rename fips FIPS
merge 1:1 FIPS using "Dataverse\Census\AgCensus1840.dta", nogen
rename FIPS fips
rename STATE icpsrstate

*** We first create a measure of the per capita output of all crops in 
*** the census. We then focus on the three major crops grown by enslaved 
*** labor: rice, tobacco, and cotton.
qui foreach x of varlist WHEATO - WINEO {
	gen `x'_percap = `x'/TOTPOP
}

*** We will merge the agricultural and cotton suitability measures back into 
*** our roll call measures below. Save this as a temporary file.
tempfile save
save `save' 

*** Examine how these three crops relate to each other in each state.
qui foreach x in TOBACO COTTONO RICEO {
	summ `x' if NAME=="VIRGINIA" & LEVEL==2
	loc VA_`x' = r(mean)
	summ `x' if NAME=="TENNESSEE"  & LEVEL==2
	loc TN_`x' = r(mean)
	summ `x' if NAME=="NORTH CAROLINA"  & LEVEL==2
	loc NC_`x' = r(mean)
}

*** Calculate the ratio's with the more important local product as the numerator
di in yellow "Virginia's ratio of tobacco to cotton output: " in red `VA_TOBACO'/`VA_COTTONO'
di in yellow "Tennessee's ratio of cotton to tobacco output: " in red `TN_COTTONO'/`TN_TOBACO'
di in yellow "North Carolina's ratio of cotton to tobacco output: " in red   `NC_COTTONO'/`NC_TOBACO'
di in yellow "North Carolina's ratio of cotton to rice output: " in red   `NC_COTTONO'/`NC_RICEO'

*** How many counties produced how much rice in each state
foreach x in 40 54 47 {
	qui count if RICE!=0 & RICE!=. & icpsrstate==`x' & LEVEL!=2
	loc count = r(N)
	qui summ RICE if icpsrstate==`x' & LEVEL==2
	loc sum = r(sum)
	
	di in yellow "State `x' -- `count' counties produced a statewide total of `sum' in rice" in red 
}

*** Table A8: "Cotton suitability and the diverse uses of enslaved labor: NC, TN, VA in 1840"
*** This table aggregates across several different regressions of per capita 
*** output and cotton suitability and slavery, and of slavery and cotton suitability. 
*** The table shows a series of bivariate relationships.
foreach x in Virginia Tennessee "North Carolina" {
	di "`x'"
	di "Tobacco"
	regress TOBACO_percap cottonsuit if state_terr=="`x'"
	di "Cotton"
	regress COTTONO_percap cottonsuit if state_terr=="`x'"
	di "Rice"
	regress RICEO_percap cottonsuit if state_terr=="`x'"
	di "Slavery"
	regress perEnslaved1830 cottonsuit if state_terr=="`x'"
}
foreach x in Virginia Tennessee "North Carolina" {
	di "`x'"
	di "Tobacco"
	regress TOBACO_percap perEnslaved1830 if state_terr=="`x'"
	di "Cotton"
	regress COTTONO_percap perEnslaved1830 if state_terr=="`x'"
	di "Rice"
	regress RICEO_percap perEnslaved1830 if state_terr=="`x'"
}

********************************************************************************
*** Now set up roll call data and merge in the agricultural data.
********************************************************************************

use "Dataverse\Files\Virginia-1831-1832-Roll-Calls.dta", clear
split district, generate(county) parse(", ")
gen state = 40
gen level = 1
gen state_id = 3
rename session year
tempfile save1
save `save1' 

use "Dataverse\Files\NC-TN-1834-1835-Roll-Calls.dta", clear
replace county = upper(county)
split county, generate(county) parse(", ")
rename county district
gen state = 47 if state_id==2
replace state = 54 if state_id==1
gen level = 1

append using `save1'
label define state_id 3 "Virginia", add

*** For multi-county districts, we need to aggregate cotton suitability. This has
*** already been done for enslaved and free Black population. The results are identical 
*** except for in TN, where a small number of delegates from multi-county districts
*** were associated with what was believed to be their home county. 
forvalue i = 1(1)7 {
di `i'
rename county`i' name
merge m:1 state name level using "Dataverse\Census\census1830.dta", keepusing(fips totpop fctot stot)
drop if _merge ==2
drop _merge
*** Don't want the missing FIPS data to merge with the value for USA.
replace fips = 999999 if fips==.
merge m:1 fips using `save'
drop if _merge == 2
drop _merge
rename name county`i'
rename fips fips`i'
rename totpop totpop`i'
rename stot stot`i'
rename fctot fctot`i'
rename cottonsuit cottonsuit_`i'
}

drop totpop1830 fctot1830 stot1830 sprop1830
egen totpop1830 = rowtotal(totpop*)
egen stot1830 = rowtotal(stot*)
egen fctot1830 = rowtotal(fctot*)
egen cottonsuit_avg = rowmean(cottonsuit_*)
gen sprop1830 = round(stot1830/totpop1830*100, 0.01)
drop totpop1-cottonsuit_1 totpop2-cottonsuit_7 

*** Include opposition to abolition in VA in the Tennessee anti-Abolition measure.
replace AntiAbolition = abs(rc1832a-1) if state==40

*** Make a combined anti-Black measure:
*** AntiBlack = bsuff, AntiAbolition, black_exclusion, rc1831a, rc1831b, rc1832c, rc1832d
*** Pro-Black = propery_black_voting, propery_black_voting2, rc1832a, rc1832b, 
tempvar a b c d 
gen `a' = abs(propery_black_voting-1)
gen `b' = abs(propery_black_voting2-1)
gen `c' = abs(rc1832a-1)
gen `d' = abs(rc1832b-1)
egen antiBlack = rowmean(bsuff AntiAbolition black_exclusion rc1831a rc1831b rc1832c rc1832d `a' `b' `c' `d')

label variable cottonsuit_avg "Cotton Suitability for districts"
label variable perEnslaved "Proportion Enslaved in districts"
label variable sprop1830 "Alternative measure of proportion enslaved in districts"
label variable antiBlack "Anti-Black voting record"

*** Identify duplicate districts (ie., multi-member districts) 
bys state year district: gen dupl = _n==1

********************************************************************************
*** Tables A4-A7
********************************************************************************

*** Table A4: "Instrumental Variables Estimates of the Effect of Slavery: NC, TN, and VA in the 1830s"
*** General, cross-state patterns
eststo clear
eststo: regress perEnslaved cottonsuit_avg perFBlack i.state
test cottonsuit_avg 47.state 54.state
eststo: ivregress 2sls bsuff perFBlack i.state (perEnslaved = cottonsuit_avg), first
eststo: ivregress 2sls AntiAbolition perFBlack i.state (perEnslaved = cottonsuit_avg), first
eststo: ivregress 2sls antiBlack perFBlack i.state (perEnslaved = cottonsuit_avg), first
*** Note that Table A4 in online appendix reports the first stage relationship from column 4
*** while the table code below reports it for the first regression above. The difference results
*** from different counties being included in the data.
esttab, se ar2 drop(*.state _cons)	stats(F N)		///
	title(Table 1)       ///
	nonumbers mtitles("Proportion Enslaved, 1830" "Support Black Disenfranchisement" "Oppose Abolition" "Averaged Anti-Black Votes")  
eststo clear

** State specific IV relationship
*** Table A5: "Virginia"
** VA
eststo: regress perEnslaved cottonsuit if state==40 & year==1831 & dupl==1
eststo: ivregress 2sls rc1831a perFBlack (perEnslaved = cottonsuit) if state==40
eststo: ivregress 2sls rc1831b perFBlack (perEnslaved = cottonsuit) if state==40
eststo: ivregress 2sls rc1832a perFBlack (perEnslaved = cottonsuit) if state==40
eststo: ivregress 2sls rc1832b perFBlack (perEnslaved = cottonsuit) if state==40
eststo: ivregress 2sls rc1832c perFBlack (perEnslaved = cottonsuit) if state==40
eststo: ivregress 2sls rc1832d perFBlack (perEnslaved = cottonsuit) if state==40
eststo: ivregress 2sls antiBlack perFBlack (perEnslaved = cottonsuit) if state==40
esttab , se ar2 drop(perFBlack _cons)	stats(F N)	replace	///
	title(Virginia) label  prehead(`"\begin{sidewaystable*}[htp!] \centering \footnotesize"' `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' `"\caption{@title}"' `"\label{tab:tableA5}"' `"\begin{tabular}{l*{@E}{c}}"' `"\hline\hline"') ///
	postfoot(`"\hline\hline"' `"\multicolumn{@span}{l}{\footnotesize Standard errors in parentheses in parentheses}\\"' `"\multicolumn{@span}{l}{\footnotesize @starlegend}\\"' `"\end{tabular}"' `"\end{sidewaystable*}"')	///
	nonumbers mtitles("Prop. Enslaved, 1830" "Restriction 1" "Restriction 2" "Abolition" "Consensual Removal" "Removal Bill" "Police Bill" "Anti-Black")   
eststo clear

*** Table A6: "Tennessee"
** TN
eststo clear
eststo: regress perEnslaved cottonsuit perFBlack if state==54
eststo: ivregress 2sls bsuff perFBlack (perEnslaved = cottonsuit) if state==54
eststo: ivregress 2sls AntiAbolition perFBlack (perEnslaved = cottonsuit) if state==54
eststo: ivregress 2sls antiBlack perFBlack (perEnslaved = cottonsuit) if state==54
esttab , se ar2 drop(perFBlack _cons)	stats(F N)	replace	///
	title(Tennessee) label  prehead(`"\begin{sidewaystable*}[htp!] \centering \footnotesize"' `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' `"\caption{@title}"' `"\label{tab:tableA6}"' `"\begin{tabular}{l*{@E}{c}}"' `"\hline\hline"') ///
	postfoot(`"\hline\hline"' `"\multicolumn{@span}{l}{\footnotesize Standard errors in parentheses in parentheses}\\"' `"\multicolumn{@span}{l}{\footnotesize @starlegend}\\"' `"\end{tabular}"' `"\end{sidewaystable*}"')	///
	nonumbers mtitles("Prop. Enslaved, 1830" "Black Disenfranchisement" "Oppose Abolition" "Averaged Anti-Black Votes")  
eststo clear

*** Table A6: "North Carolina"
** NC
eststo: regress perEnslaved cottonsuit if state==47
eststo: ivregress 2sls bsuff perFBlack (perEnslaved = cottonsuit) if state==47
eststo: ivregress 2sls black_exclusion perFBlack (perEnslaved = cottonsuit) if state==47
eststo: ivregress 2sls propery_black_voting perFBlack (perEnslaved = cottonsuit) if state==47
eststo: ivregress 2sls propery_black_voting2 perFBlack (perEnslaved = cottonsuit) if state==47
eststo: ivregress 2sls antiBlack perFBlack (perEnslaved = cottonsuit) if state==47
esttab , se ar2 drop(perFBlack _cons)	stats(F N)	replace	///
	title(North Carolina) label  prehead(`"\begin{sidewaystable*}[htp!] \centering \footnotesize"' `"\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"' `"\caption{@title}"' `"\label{tab:tableA7}"' `"\begin{tabular}{l*{@E}{c}}"' `"\hline\hline"') ///
	postfoot(`"\hline\hline"' `"\multicolumn{@span}{l}{\footnotesize Standard errors in parentheses in parentheses}\\"' `"\multicolumn{@span}{l}{\footnotesize @starlegend}\\"' `"\end{tabular}"' `"\end{sidewaystable*}"')	///
	nonumbers mtitles("Prop. Enslaved, 1830" "Disenfranchisement 1" "Disenfranchisement 2" "Limited enfranchisement 1" "Limited enfranchisement 2" "Anti-Black")  
eststo clear

********************************************************************************
*** Figure A8: "Cotton Suitability, Enslavement, and Tobacco or Rice Cultivation, North Carolina"
*** The cotton suitability instrument is of limited use in North Carolina, where
*** enslavement was widely used for other crops that did not correlate strongly 
*** with cotton suitability. 

*** Identify NC counties above the 60th percentile in tobacco or rice production.
summ TOBACO_percap RICEO_percap if icpsrstate==47, det
gen non_cotton = (TOBACO_percap>.2 | RICEO_percap>0)

tw scatter perEnslaved cottonsuit if icpsrstate==47 & non_cotton==0, mlw(thin) mlc(black) mcol(navy) 	///
	|| scatter perEnslaved cottonsuit if icpsrstate==47 & non_cotton==1, msy(Th) mlw(thin) mlc(black) 	///
	graphreg(color(white)) ylabel(, nogrid angle(h) labsize(small)) ytitle("County Enslavement", size(small))	///
	xlab(, labsize(small)) xtitle("Cotton Suitability", size(small)) legend(off) 						///
	note("Triangles are those counties above the 60th percentile in tobacco or rice production.", size(vsmall))

graph export "Dataverse\Figures\Figure-A8.pdf", as(pdf) replace

*** Calculate the proportion of delegates from cotton and non-cotton counties that
*** voted for black disenfranchisement. The relationship with enslavement is 
*** positive and significant in both sets of counties.
summ bsuff if non_cotton==1 & state==47
summ bsuff if non_cotton==0 & state==47

regress bsuff perEnslaved i.non_cotton if state==47
regress bsuff c.perEnslaved##i.non_cotton if state==47

********************************************************************************
*** Show the relationship between levels of enslavement in 1830, 1850 and 1860 
********************************************************************************

use "Dataverse\Census\census1830.dta", clear
keep state name level fips totpop stot
rename totpop totpop1830
rename stot stot1830

merge m:1 state name level using "Dataverse\Census\census1850.dta", keepusing(fips totpop stot)
rename totpop totpop1850
rename stot stot1850
drop _merge

merge m:1 state name level using "Dataverse\Census\census1860.dta", keepusing(fips totpop stot)
rename totpop totpop1860
rename stot stot1860

gen perEnslaved1830 = round(stot1830/totpop1830*100,0.01) 
gen perEnslaved1850 = round(stot1850/totpop1850*100,0.01) 
gen perEnslaved1860 = round(stot1860/totpop1860*100,0.01) 

foreach x in 54 47 40 46 44 {
	if `x' ==54 {
		loc title = "Tennessee"
	}
	if `x' ==47 {
		loc title = "North Carolina"
	}
	if `x' ==40 {
		loc title = "Virginia"
	}
	if `x' ==46 {
		loc title = "Mississippi"
	}
	tw scatter perEnslaved1860 perEnslaved1830 if state==`x', 			///
			msym(O) mcol(white) mlc(black) mlw(thin) 					///
		|| lfit perEnslaved1860 perEnslaved1830 if state==`x', 			///
			lp(dash) lc(black)											///
		|| function y = x, range(0 100) lcol(black) lw(thin)			///
		, graphreg(col(none)) ytitle("% Enslaved 1860", size(small))	///
		xtitle("% Enslaved 1830", size(small)) 							///
		ylab(0(20)100, grid angle(h) labsize(small) glcol(gs13) glw(vthin))					///
		xlab(0(20)100, grid angle(h) labsize(small) glcol(gs13) glw(vthin)) title("`title'", col(black) size(small))	///
		legend(order(1 2) label(1 "County") size(small)) name(state`x', replace)
}

*** Figure A9: "County-level percentage enslaved in Tennessee and North Carolina, 1830 to 1860"
grc1leg state54 state47, graphreg(col(white)) imargin(tiny)
graph export "Dataverse\Figures\Figure-A9.pdf", as(pdf) replace
*** Figure A10: "County-level percentage enslaved in Virginia and Mississippi, 1830 to 1860"
grc1leg state40 state46, graphreg(col(white)) imargin(tiny)
graph export "Dataverse\Figures\Figure-A10.pdf", as(pdf) replace

foreach x in 46 44 {
	if `x' ==44 {
		loc title = "Georgi"
	}
	if `x' ==46 {
		loc title = "Mississippi"
	}
	tw scatter perEnslaved1860 perEnslaved1850 if state==`x', 			///
			msym(O) mcol(white) mlc(black) mlw(thin) 					///
		|| lfit perEnslaved1860 perEnslaved1850 if state==`x', 			///
			lp(dash) lc(black)											///
		|| function y = x, range(0 100) lcol(black) lw(thin)			///
		, graphreg(col(none)) ytitle("% Enslaved 1860", size(small))	///
		xtitle("% Enslaved 1850", size(small)) 							///
		ylab(0(20)100, grid angle(h) labsize(small) glcol(gs13) glw(vthin))					///
		xlab(0(20)100, grid angle(h) labsize(small) glcol(gs13) glw(vthin)) title("`title'", col(black) size(small))	///
		legend(order(1 2) label(1 "County") size(small)) name(state`x', replace)
}

*** Figure A11: "County-level percentage enslaved in Georgia and Mississippi, 1850 to 1860"
grc1leg state44 state46, graphreg(col(white)) imargin(tiny)
graph export "Dataverse\Figures\Figure-A11.pdf", as(pdf) replace
